cars = ['bmw','audi','toyota','subaru']

# sorted() 临时排序
print("temporary:")
print(sorted(cars))  # 正序
print("temporary:")
print(sorted(cars,reverse=True))  # 倒序
print("original:")
print(cars) 


# 倒着打印列表
cars.reverse()
print("inverted:")
print(cars)


# sort() 永久性排序
print('permanent:')
cars.sort()  # 按照字母进行永久性排序
print(cars)  
print('inverted permanent:')
cars.sort(reverse=True)
print(cars)


# len() 获取列表长度
print(len(cars))


# 列表循环
magicians = ['alice','david','carolina']

for magician in magicians:
    print(magician)
    print("------")  # 缩进的代码行是循环的一部分

print("over!\n\n\n")


# 随机函数range()
for value in range(95,100):
    print(value)

# 列表函数list()
numbers = list(range(95,100)) 
print(numbers)

even_number = list(range(80,89,2))
print(even_number)


squares = []
for value in range(1,11):
    square = value**2
    squares.append(square)
print(squares)


# 对数字列表执行简单的统计计算
digits = list(range(0,11))
print(digits)
print("min:"+str(min(digits)))
print("max:"+str(max(digits)))
print("sum:"+str(sum(digits)))


# 列表解析
squares = [value**2 for value in range(1,11)]
print(squares)


squares = [value for value in range(1,100001)]
print(sum(squares))



# 处理列表的部分元素-切片
players =["charles", "martina", "michael", "florence", "eli"]
print(players[2:])  # 如果没有指定起始索引，python列表从头开始提取
print(players[:2])  # 如果没有指定末尾索引，python列表终止于末尾
print(players[2:-1])
print(players[2:3])


for players in players[2:]:
    print("-!- "+players)

# 复制列表
my_foods = ["pizza", "falafel", "carrot", "cake"]
friend_foods = my_foods[:]

my_foods.append("apple")
friend_foods.append("beef")

print(my_foods)
print(friend_foods)


# 元组 --不可变的列表  使用圆括号()
dimensions = (200,50)
print(dimensions[0])
print(dimensions[1])

# 修改不可变的元组--给存储元组的变量赋值
dimensions = (100, 99, 88)
print(dimensions[0])
print(dimensions[1])
print(dimensions[2])




